home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-06 | 3.4 KB | 179 lines | [TEXT/MSET] |
- (*
-
- Class SelWindow is a window that handles objects that can be selected.
- The idea here is to provide a standard protocol for all (most?) selectable objects.
- Any such object must properly respond to a standard set of messages. The advantages
- of following this framework protocol is it becomes rather easy to implement the
- standard Macintosh user interface. Selecting and interacting with objects is
- automatic.
-
-
-
- The protocol messages are as follows, most methods will be self explanatory.
-
- new: ( wptr -- ) perform any one-time initialization, called along with new: to window
- activate: what to do when the window activates
- deactivate: what to do when the window deactivates
- idle: The currently selected object will receive idle messages when the window does.
- draw:
-
- click:
- key: ( char -- )
- release: will be called upon a close: to the window
- hit?: ( -- b ) true if the mouse "hit" on the object, only call after a mouse down
- alwaysActive?: ( -- b)
- focus?: ( -- b) return true if this object should receive keystrokes or clipboard
- messages once it is selected. Note that only one object at a time may have the
- focus. For example, we would not want to send the same keboard input to more than
- one textedit object at the same time (at least that's the way we do things here).
-
- cut:
- copy:
- paste:
- clear:
-
- *)
-
- :CLASS selWindow super{ primitiveWin }
- var currentSel \ the currently selected object; could be a nullSelect
- ptrlist SelList \ a list of objects that can be selected
-
- :m add: { ^obj -- }
- alive: super
- IF
- self new: ^obj
- draw: ^obj
- ^obj add: SelList
- ELSE ." can't add: objects unless a selwindow is new" abort
- THEN
- ;m
-
-
- :m enable: { \ next -- }
- enable: super
- get: currentSel activate: **
-
- BEGIN
- each: SelList
- WHILE
- -> next
- alwaysActive?: next
- get: currentSel next <> and \ if currentSel is already active don't do it again
- IF activate: next THEN
- REPEAT
- ;m
-
- :m disable:
- BEGIN
- each: SelList
- WHILE
- deactivate: **
- REPEAT
-
- disable: super ;m
-
- :m idle:
- get: currentSel idle: **
- ;m
-
-
- :m draw:
- BEGIN
- each: SelList
- WHILE
- draw: **
- REPEAT
- ;m
-
- private
-
- :m doContent: { \ next -- } \ Must look for a hit on an object in the list.
- BEGIN
- each: SelList
- WHILE
- -> next
- hit?: next
- IF
- \ You hit something. Is it already the current selection?
- next get: currentSel =
- IF
- \ You hit the current selection, so do its click method.
- click: next ( next = currentSel )
- ELSE
- \ you hit a different object, so...
- focus?: next IF
- \ we must change the focus to the next object
- get: currentSel deactivate: **
- activate: next
- draw: next
- next put: currentSel
- ELSE
- \ don't change the focus, just do a click:
- click: next
- THEN
- THEN
- uneach: SelList exit \ must stop this method here
- THEN
- REPEAT
- ;m
-
- public
-
- :m content:
- active: self
- IF
- doContent: self
- ELSE
- select: self
- THEN ;m
-
- :m key: ( char -- )
- get: currentSel key: ** ;m
-
- :m cut:
- get: currentSel cut: ** ;m
-
- :m copy:
- get: currentSel copy: ** ;m
-
- :m paste:
- get: currentSel paste: ** ;m
-
- :m clear:
- get: currentSel clear: ** ;m
-
- :m new: ( taddr tlen procID vis goaway -- )
- new: super
- new: SelList
- tnullselect put: currentSel
- ;m
-
- :m makeCurrent: ( addr -- )
- put: currentSel ;m
-
- :m getnew: ( resid -- )
- getnew: super
- new: SelList
- tnullselect put: currentSel
- ;m
-
- :m close:
- BEGIN
- each: SelList
- WHILE
- release: **
- REPEAT
- release: selList
- close: super
- ;m
-
- ;CLASS
-
- endload
-
-
- *** EXAMPLE USE
-
- selwindow w
- test: w
-